package com.haoshuang.zhouzhoubang.ui.page.settled.settled

import com.haoshuang.zhouzhoubang.base.BaseCommonViewModel
import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.CooperationTimeBean
import com.haoshuang.zhouzhoubang.model.bean.IDCardBean
import com.haoshuang.zhouzhoubang.model.bean.SettledInfoBean
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class StoreSettledInputViewModel : BaseCommonViewModel() {

    /**
     * 获取合作期限
     */
    val getCooperationPeriodData =
        StatefulMutableLiveData<ResponseBean<MutableList<CooperationTimeBean>>>()

    fun getCooperationPeriod(city: String?) = netRequest {
        start { getCooperationPeriodData.value = StateData.Loading }
        request { ApiRepo.getCooperationPeriod(city) }
        success { getCooperationPeriodData.value = StateData.Success(it) }
        error { code, msg ->
            getCooperationPeriodData.value = StateData.Error(code, msg)
        }
    }

    /**
     * applySettled
     */
    val applySettledData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun applySettled(settledInfoBean: SettledInfoBean?, is_edit: Int?,Address: String?,
                     BirthDate: String?,
                     EndDate: String?,
                     Gender: String?,
                     IDNumber: String?,
                     Issue: String?,
                     Name: String?,
                     Nationality: String?,
                     StartDate: String?) = netRequest {
        start { applySettledData.value = StateData.Loading }
        request {
            ApiRepo.applySettled(
                settledInfoBean?.real_name,
                settledInfoBean?.mobile,
                settledInfoBean?.card_front,
                settledInfoBean?.card_side,
                settledInfoBean?.team_name,
                settledInfoBean?.team_logo,
                settledInfoBean?.team_num.toString(),
                settledInfoBean?.team_company_pic,
                settledInfoBean?.team_side_logo,
                settledInfoBean?.team_right_logo,
                settledInfoBean?.synopsis,
                settledInfoBean?.province,
                settledInfoBean?.city,
                settledInfoBean?.area,
                settledInfoBean?.address,
                settledInfoBean?.lng,
                settledInfoBean?.lat,
                settledInfoBean?.service_year.toString(),
                settledInfoBean?.service_id,
                is_edit,
                settledInfoBean?.is_entity,
                Address,BirthDate,EndDate,Gender,IDNumber,Issue,Name,Nationality,StartDate
            )
        }
        success { applySettledData.value = StateData.Success(it) }
        error { code, msg ->
            applySettledData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 门店入驻信息回显
     */
    val getStoreSettledInfoData = StatefulMutableLiveData<ResponseBean<SettledInfoBean>>()
    fun getStoreSettledInfo() = netRequest {
        start { getStoreSettledInfoData.value = StateData.Loading }
        request { ApiRepo.getStoreSettledInfo() }
        success { getStoreSettledInfoData.value = StateData.Success(it) }
        error { code, msg ->
            getStoreSettledInfoData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 身份证识别
     */
    val idCardRecognitionData = StatefulMutableLiveData<IDCardBean>()
    fun idCardRecognition(card_front: String, card_side: String) = netRequest {
        start { idCardRecognitionData.value = StateData.Loading }
        request { ApiRepo.idCardRecognition(card_front, card_side)  }
        success { idCardRecognitionData.value = StateData.Success(it.data) }
        error { code, msg ->
            idCardRecognitionData.value = StateData.Error(code, msg)
        }
    }

}